package cn.madis.ymcc.web.controller;

import cn.madis.ymcc.dto.MobilePhoneRegisteredDto;
import cn.madis.ymcc.result.JSONResult;
import cn.madis.ymcc.service.IVerifycodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/verifycode")
public class VerifycodeController {

    @Autowired
    private IVerifycodeService verifycodeService;

    @PostMapping("/sendSmsCode")
    public JSONResult sendSmsCode(@RequestBody @Valid MobilePhoneRegisteredDto dto){
        return verifycodeService.phoneRegister(dto);
    }

    @GetMapping("/imageCode/{imageCodeKey}")
    public JSONResult imageCode(@PathVariable("imageCodeKey") @Valid String imgCodeKey){
        String base64Str = verifycodeService.graph(imgCodeKey);
        return JSONResult.success(base64Str);
    }
}
